﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;
using WebApplication1.App_Data.ProeftuinDSTableAdapters;

namespace WebApplication1
{
    /// <summary>
    /// Summary description for WebServiceStudentData
    /// </summary>
    [WebService(Namespace = "http://www.hszuyd.nl/wtbas/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    public class WebServiceStudentData : System.Web.Services.WebService
    {
        [WebMethod]
        public DataTable GetStudentData(int studentNummer)
        {
            StudentenTableAdapter studentenTableAdapter = new StudentenTableAdapter();
            return FlipDataSet(studentenTableAdapter.GetDataViaStudentNummer(studentNummer));
        }

        private DataTable FlipDataSet(DataTable Datatabel)
        {
            DataTable table = new DataTable();

            for (int i = 0; i <= Datatabel.Rows.Count; i++)
            {
                table.Columns.Add(i.ToString());
            }

            DataRow r = null;

            for (int k = 0; k < Datatabel.Columns.Count; k++)
            {
                r = table.NewRow();
                r[0] = Datatabel.Columns[k].ToString();
                for (int j = 1; j <= Datatabel.Rows.Count; j++)
                {
                    r[j] = Datatabel.Rows[j - 1][k];
                    table.Rows.Add(r);
                }
            }
            return table;
        }

    }
}
